//
//  ViewController.m
//  03-手势
//
//  Created by dllo on 16/7/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()


@end

@implementation ViewController


//- (void)loadView
//{
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//    tap.numberOfTapsRequired = 2;//点击几次触发，默认为1
//    tap.numberOfTapsRequired = 3;//几个手指触发（按option - alt）默认为1
//    [self.view addSubview:tap];
//    //    手势识别器（7种）
//    
//    //    轻拍 Tap
//    //长按
//    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
//    [self.view addSubview:longPress];
//}


- (void)viewDidLoad {
    [super viewDidLoad];
//     Do any additional setup after loading the view, typically from a nib.
//    self.view.backgroundColor = [UIColor redColor];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tap.numberOfTapsRequired = 2;//点击几次触发，默认为1
    tap.numberOfTapsRequired = 3;//几个手指触发（按option - alt）默认为1
    [self.view addGestureRecognizer:tap];
//    手势识别器（7种）
    
    //    轻拍 Tap
    //长按
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
    longPress.allowableMovement = 10;//默认10像素，长按失败前，最大的移动距离
    longPress.minimumPressDuration = 3;//长按几秒后开始，默认0.5秒
    [self.view addGestureRecognizer:longPress];
    
    
    //    轻扫
    
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//    direction可以设置多个，前提多个方向所触发的行为要相同
//    如果多个方法触发的行为不同，需要创建多个清扫的手势
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipe];
//    练习：imageView添加清扫换图
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(10, 10, 200, 340);
    imageView.image = [UIImage imageNamed:@"1"];
    [self.view addSubview:imageView];
    
    UISwipeGestureRecognizer *swipe1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeChangeImageLft:)];
    imageView.userInteractionEnabled = YES;//将图片的交互打开
    [imageView addGestureRecognizer:swipe1];
    //胺位枚举，4个选项-》1，1，1，1
//    全选的情况 1（4） 1（3）1（2）1(0)
    //    平移
    //    捏合
    //    旋转
    //    屏幕边缘手势
}

- (void)swipeChangeImageLft:(UISwipeGestureRecognizer *)swipe
{
    UIImageView *imageView = (UIImageView *)swipe.view;
    imageView.image = [UIImage imageNamed:@"1"];
    
}
- (void)swipeChangeImageRight:(UISwipeGestureRecognizer *)swipe1
{
    NSLog(@"ld",swipe1.direction);
    if (swipe1.direction == UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"1111");
    } 
}


- (void)swipeAction:(UISwipeGestureRecognizer *)swipe {
    NSLog(@"轻扫");
}

- (void)tapAction:(UITapGestureRecognizer *)tap
{
    NSLog(@"轻拍");
}

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
    NSLog(@"长按");
    if (longPress.state == UIGestureRecognizerStateBegan) {
        NSLog(@"长按开始");
    } else if (longPress.state == UIGestureRecognizerStateEnded) {
        NSLog(@"长按结束");
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
